/**
 * 造型
 * author:noodles
 * 主玩家、客户端玩家、NPC等角色的基本模型。实现了换装、移动、说话、头顶动画等功能。
 * 先用changBodyPart方法加载服饰，交由design加载服饰的二进制压缩数据以及解压。
 * 完成初始化后再调用beginMove方法来让角色移动。
 * 该类的父类可改成Sprite。onEnterFrameHandle将改用时钟触发。新增功能请不要使用该类的Movieclip特有属性
 * 
 * 帧矩阵中的各方向帧所在的行顺序
 * 左下0行
 * 右下0行
 * 左上1行
 * 右上1行
 * 前  2行
 * 后  3行
 * 左  4行
 * 右  4行
 * */
package com.gamebase.role
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.TimerEvent;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.utils.Dictionary;
	import flash.utils.Timer;
	import flash.utils.clearTimeout;
	import flash.utils.setTimeout;
	import com.gamebase.role.vo.Direction;
	import com.gamebase.role.vo.AvatarType;
	import com.gamebase.role.vo.AvatarEventConst;
	
	
	public class Avatar extends Sprite
	{
		private var design:Design;//服饰管理器
		protected var avatarType:uint = AvatarType.NPC;
//		protected var m_PicHeight:int;
		public var roleWalkLenList:Array = [23,13,15,15,13,12,20];//同方向移动的步长列表
		public var roleRunLenList:Array = [38,26,50,38,26,50,38];
		public var roleJumpLenList:Array = [25,25,25];
		protected var lastFrame:uint = 0;//前一帧的序号，从0开始
		
		private var m_CurNodeIndex:uint;//当前行走到的节点标记（递减）
		private var subPathLen:int;//当前行走子路段总长
		private var subPath:Array;//当前子路径的两个端点
		private var subPathPassLen:Number;//当前子路段已经行走的长度
		private var subNodeIndex:uint;//当前子路段的当前节点标记（递增）
		public var m_MoveAngle:Number;//当前行走的角度
		private var m_PathArr:Array=new Array();//NPC行走路径列表
		public var  m_DicValue:int;//移动方向值，为120表示已经静止
//		protected var walkStepLen:int = 10;
//		protected var runStepLen:int = 30;
		public var moveStepLen:int = 10;//移动步长
		protected var m_MoveFrame:int = 2;//移动一步的耗时，单位为时间轴移动一帧所需要的时间
		public var m_MoveStep:int;//用于延迟角色移动频率，与m_MoveFrame相等时触发一次移动
		protected var m_RoleBitDataMap:BitmapData;//角色装配叠加好后的各个方向的矩阵位图
//		private var walkBitDataMap:BitmapData;
//		private var runBitDataMap:BitmapData;
//		private var jumpBitDataMap:BitmapData;
		
		protected var m_RoleBitData:BitmapData;//切割出来的单帧位图数据
		public var m_RoleBitMap:Bitmap;//切割出来的单帧位图
		protected var standBitmapData:BitmapData;
		protected var standBitmap:Bitmap;
		protected var m_RolePoint:Point;

		public var realTop:int;//模型的实体顶点Y坐标
		public var realBottom:int;//模型的实体底部Y坐标
		protected var bitmapOffsetX:int;//更改注册点时的x轴偏量
		protected var headMovieSprite:Sprite;//头部动画容器
		protected var headMovieLoader:Loader;//头部动画加载器
		protected var headMovieTimer:Timer;//头部动画计时器
		protected var headMovieTime:uint;//头部动画持续时间
		protected var headMovieMarginTop:int//头部动画距头顶的距离
		protected var m_RoleRecngle:Rectangle;//但帧位图切割矩形
		protected var standRectangle:Rectangle;
		public var directionName:String = Direction.LeftFront;//站立方向
		protected var actionSprite:Sprite;//动作动画容器
		
		private var defaultMultiAction:AvatarMC;//默认多部位角色的动作动画
		private var defaultSingleAction:MovieClip;//默认单部位动作动画
		private var multiPartActionMC:AvatarMC;//多部位角色的动作动画
		private var actionMC:MovieClip;//第一个有效部位动作动画
		
		private var _actionID:uint=0;//当前动作动画ID
	 	public var m_GameStop:Boolean=true;//行走开关
	 	protected var _status:String;//移动方式：走、跑、跳等
	 	private var _natureStatus:String;//角色的默认移动方式
	 	protected var _actionTime:Number;//动作动画播放时间
	 	protected var relaxTimeHandle:uint = 0;//休闲动画延时句柄
	 	private var timeOutHandle:uint = 0;//休闲动画移除句柄
		protected var moveOverCallBack:Function;//移动完成回调
		public var _onMoveStepFun:Function;//每移动一步的回调
		
		/**鼠标碰撞非空像素检查变量*/ 
		private var hitTestBMD:BitmapData;//用于检查鼠标是否与非空像素碰撞
		private var hitTestRec:Rectangle;
		
		/**
		 * @param changePartList:结构为[[part:String,partURL:String],[]...]，part值为："all","head","body","leg","feet"
		 * @param natureStatus:角色的默认移动方式
		 * */
		public function Avatar( natureStatus:String="walk", changePartList:Array=null, $onMoveStepFun:Function=null)
		{
			super();
			_natureStatus = natureStatus;
			_onMoveStepFun = $onMoveStepFun;
			_status = _natureStatus;
			design = new Design();
			
			m_MoveStep = 1;
			m_DicValue = 10;
			m_RolePoint = new Point(0,0);
			if(changePartList)
				changBodyPart(changePartList);
			
		}
		
		/**改变移动方式:站、走、跑、跳等移动方式状态。注意：默认移动方式的资源里包含有站立资源
		 * 设置被剪切位图数据m_RoleBitDataMap、剪切矩形m_RoleRecngle。
		 * @param status:"stand"、"run"、"walk"、"jump"
		 * */
		private function changeMoveType(status:String = null,cb:Function=null,param:Object=null):void
		{
			if(design.lock)
			{
				trace("资源未提取");
				status = _natureStatus;
				moveStart();
				return;
			}
			if((status == _status) || status==null)
			{
				return;
			}
			
			var totalCol:uint = 1;//资源中一行个体数
			var totalRow:uint = 1;//资源中一列个体数
			var ceilWidth:int;
			var drawWidth:int;
			var drawMatrix:Matrix = new Matrix();
			var mcName:String;
			
			mcName = status;
			if(status=="walk")
			{
				totalCol = 7;
				totalRow = 5;
			}
			else if(status=="run")
			{
				totalCol = 6;
				totalRow = 5;
			}
			else if(status=="jump")
			{
				totalCol = 2;
				totalRow = 5;
			}
			
			//展开压缩资源
//tt			design.getDesign(onDesignGet);
			
			function onDesignGet():void
			{
				//获取m_RoleBitDataMap资源
				if(design == null)
				{
					trace("资源解压后获取资源异常");
					return;
				}
				if(m_RoleBitDataMap != null)
					m_RoleBitDataMap.dispose();
				
				var toDrawObject:DisplayObject;//绘制对象
				if(design.isAllPart())//如果角色各部位是由整张图片构成
				{
					if(design.all.hasOwnProperty(mcName))//如果资源MC已经命名（老的资源没命名）
						toDrawObject = design.all[mcName];
					else
//tt						toDrawObject = design.all;
					
					ceilWidth = Math.round(toDrawObject.width/totalCol);
					if(status == _natureStatus)
					{
						drawMatrix.tx = -ceilWidth;
						drawWidth = toDrawObject.width - ceilWidth;
					}
					else
					{
						drawWidth = toDrawObject.width;
					}
					m_RoleBitDataMap = new BitmapData( drawWidth,toDrawObject.height,true,0x00 );
					m_RoleBitDataMap.draw(toDrawObject,drawMatrix);
				}
				else//如果角色各部位是由头、身体、腿、脚构成
				{
					if(design.head.hasOwnProperty(mcName))
						toDrawObject = design.head[mcName];
					else
//tt						toDrawObject = design.head;
					ceilWidth = Math.round(toDrawObject.width/totalCol);
					if(status == _natureStatus)
					{
						drawMatrix.tx = -ceilWidth;
						drawWidth = toDrawObject.width - ceilWidth;
					}
					else
					{
						drawWidth = toDrawObject.width;
					}
					m_RoleBitDataMap = new BitmapData( drawWidth,toDrawObject.height,true,0x00 );
					m_RoleBitDataMap.draw(design.feet[mcName],drawMatrix);
					m_RoleBitDataMap.draw(design.leg[mcName],drawMatrix);
					m_RoleBitDataMap.draw(design.body[mcName],drawMatrix);
					m_RoleBitDataMap.draw(design.head[mcName],drawMatrix);
				}
				//设置剪切矩形框
				m_RoleRecngle.width = int(toDrawObject.width/totalCol);
				m_RoleRecngle.height = int(toDrawObject.height/totalRow);
				toDrawObject = null;
				_status = status;
				
				makeFrame();
				if(cb!=null)
				{
					if(param!=null)
						cb(param);
					else
						cb();
					cb = null;
				}
				
			}
		}
		
		//生成角色单帧形象
		private function makeFrame():void
		{
			if(m_RoleBitData != null) m_RoleBitData.dispose();
			m_RoleBitData = new BitmapData( m_RoleRecngle.width,m_RoleRecngle.height,true,0x00);
			m_RoleBitMap  = new Bitmap(m_RoleBitData);
			
			m_RoleBitMap.scaleX = 1;
			//清空单个角色资源 	
			if(m_RoleBitMap !=null && m_RoleBitMap.parent!=null)
			{
				this.removeChild(m_RoleBitMap);
			}
			this.addChild(m_RoleBitMap);
			
			bitmapOffsetX = int(m_RoleRecngle.width/2);
			
//			switch(_status)
//			{
//				case _natureStatus:
//				{
//					
//					break;
//				}
//				case "run":
//				{
//					
//					moveStepLen = this.runStepLen;
//					//this.updateSpead(1);
//					break;
//				}
//				case "walk":
//				{
//					moveStepLen = this.walkStepLen;
//					//this.updateSpead(3);
//					break;
//				}
//			}
//			moveFront();
			standDirection(directionName);
			this.realBottom = m_RoleRecngle.height;
			this.realTop = 0;
			scan();
			layout();
			if(hitTestBMD!=null)
				hitTestBMD.dispose();
				
			hitTestBMD= new BitmapData(m_RoleRecngle.width,m_RoleRecngle.height,true,0);
			if(hitTestRec == null)
				hitTestRec = new Rectangle(0,0,1,1);
		}
		
		//播放默认动作动画
		public function doDefaultAction():void
		{
			var relaxDivTime:uint 
			if(avatarType == AvatarType.PLAYER)
				relaxDivTime= Math.ceil((4 + Math.random()*5)*1000);
			else
				relaxDivTime= Math.ceil((3 + Math.random()*5)*1000);
				
			if(relaxTimeHandle != 0)
			{
				flash.utils.clearTimeout(relaxTimeHandle);
				if(avatarType == AvatarType.PLAYER)
					doAction(0,null,null,Math.ceil((1+Math.random()*3)));
				else
					doAction(0,null,null,0);
			}
			relaxTimeHandle = flash.utils.setTimeout(doDefaultAction,relaxDivTime);
				
		}
		
		//更新移动速度
		public function updateSpead(s:int=2):void
		{
			m_MoveFrame = s;
		}
	
		/**更改角色身体部位
		 *  @param changePartList:结构为[[part:String,partURL:String],[]...]，part值为："all","head","body","leg","feet"
		 * */
		public function changBodyPart(changePartList:Array):void
		{
			var designDic:Dictionary = new Dictionary();
			var i:uint=0;
			while(i<changePartList.length)
			{
				designDic[changePartList[i][0]] = changePartList[i][1];
				i++;
			}
//tt			design.ini(designDic,onDesignLoadOver);
		}
		
		
		//弹出说话泡泡
		public function popSpeak(words:String,delay:Number=2):void
		{
			setHeadMovie("assets/swf/popChat.swf",delay);
			words = words.length<45 ? words : words.substr(0,44)+"...";
			var wordsTextField:TextField = new TextField();
			wordsTextField.multiline = true;
			wordsTextField.wordWrap = true;
			wordsTextField.width=190;
			wordsTextField.maxChars=45;
			wordsTextField.text = words;
			var textFormat:TextFormat = new TextFormat(null,null,0xffffff,null,null,null,null,null,"center");
			wordsTextField.setTextFormat(textFormat);
			wordsTextField.autoSize = TextFieldAutoSize.CENTER;
			wordsTextField.x = -wordsTextField.width*0.5;
			wordsTextField.y =  -(90 - wordsTextField.height)*0.5 - wordsTextField.height ;
			headMovieSprite.addChild(wordsTextField);
		}
		
		/**设置头部动画
		 * @parma singleMode:是否只允许同时设置一个
		 * @parma resource:资源地址(String)或者显示对象(DisplayObject)，目标可以是swf或者图片
		 * @parma delayTime:持续时间，0为永久播放。-1为永久播放。单位：秒
		 * @parma marginTop:距顶部距离，默认10像素。且居中对齐
		 * */
		public function setHeadMovie(resource:Object,delayTime:int=0 ,marginTop:int=10,singleMode:Boolean=true):void
		{
			if(headMovieLoader == null) headMovieLoader = new Loader();
			headMovieTime = delayTime;
			headMovieMarginTop = marginTop;
			if(headMovieSprite == null)
			{
				headMovieSprite = new Sprite();
				this.addChild(headMovieSprite);
				headMovieSprite.x = 0;
				headMovieSprite.y = -realBottom+realTop;
			}
			else
			{
				if(singleMode)
				{
					while(headMovieSprite.numChildren > 0)
					{
						headMovieSprite.removeChildAt(0);
					}
				}
			}
			if(resource is String)
			{
				headMovieLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,addHeadMovie);
				headMovieLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onIOError);
				headMovieLoader.load(new URLRequest(resource as String));
			}
			else
			{
				addHeadMovie(null,resource as DisplayObject);
			}
		}
		
		protected function addHeadMovie(evt:Event = null,movie:DisplayObject=null):void
		{
			var obj:*
			if(movie != null)
				obj = movie;
			else if(headMovieLoader.content is DisplayObject)
				obj =headMovieLoader.content;
			else
				return;
			headMovieSprite.addChild(obj);
			headMovieSprite.setChildIndex(obj,0);//为了不当住上面可能有的文字
			obj.x=-obj.width/2;
			obj.y=-obj.height-headMovieMarginTop;
			if(headMovieTime == 0)//播放到最后一帧卸载
			{
				if(obj is MovieClip)
				{
					obj.addEventListener(Event.ENTER_FRAME,
					function():void{if(obj.currentFrame == obj.totalFrames) headMovieSprite.removeChildAt(0)}
					,false,0,true);
				}
			}
			else if(headMovieTime == -1)//永久播放
			{
				
			}
			else//按指定时间播放
			{
				if(headMovieTimer == null)
				{
					headMovieTimer = new Timer(1000,headMovieTime);
					headMovieTimer.addEventListener(TimerEvent.TIMER_COMPLETE,removeHeadMovie);
				}
				else
				{
					headMovieTimer.stop();
					headMovieTimer.reset();
					headMovieTimer.repeatCount = headMovieTime;
				}
				headMovieTimer.start();
			}
				
		}
		
		public function removeHeadMovie(evt:TimerEvent=null):void
		{
			if(headMovieTimer != null) headMovieTimer.stop();
			while(headMovieSprite.numChildren > 0)
			{
				headMovieSprite.removeChildAt(0);
			}
			headMovieLoader.unload();
		}
		
		
		/**让角色移动
		 * 按movePath给定的路径开始移动
		 * */
		public function beginMove(movePath:Array,cb:Function=null,moveType:String=null):void
		{
			m_GameStop = true;
			if(movePath.length < 2)
			{
				trace("路径异常："+movePath);
				if(cb != null) cb.call();
				return;
			}
			m_PathArr = movePath.slice();
			moveOverCallBack=cb;
			if((moveType != null)&&(_status != moveType))
			{
				changeMoveType(moveType,moveStart);
			}
			else
			{
				moveStart();
			}
		}
		
		private function moveStart():void
		{
			m_CurNodeIndex = m_PathArr.length - 1;
			actionOver();
			MoveToNextNode();
			
		}
		
		
		//=====================以下方法为从矩阵位图中切割单帧===================
		protected function moveFront():void{
			if(m_RoleBitDataMap == null) return;
		
			m_RoleRecngle.y = m_RoleRecngle.height*2;
			if( m_RoleRecngle.right+m_RoleRecngle.width>m_RoleBitDataMap.width)
			    m_RoleRecngle.x = 0;
			else
			    m_RoleRecngle.x += m_RoleRecngle.width;
				
			m_RoleBitData.copyPixels(m_RoleBitDataMap,m_RoleRecngle,m_RolePoint);
			m_RoleBitMap.scaleX = 1;
			m_RoleBitMap.x = (-bitmapOffsetX); 
		}
		
		public function stopFront():void{
			
			if(standBitmapData!=null && m_RoleBitData!=null && m_RoleBitMap!=null)
			{
				standRectangle.y = m_RoleRecngle.height*2;	
				//m_RoleBitData.fillRect(m_RoleRecngle,0);
				clearBitmapdata()
				m_RoleBitData.copyPixels(standBitmapData,standRectangle,m_RolePoint);
				m_RoleBitMap.scaleX = 1;
				m_RoleBitMap.x = (-bitmapOffsetX);
			}
			endMove();
		}
		
		protected function moveBack():void
		{
			if(m_RoleBitDataMap == null) return;
		    m_RoleRecngle.y= m_RoleRecngle.height*3;
			
			if( m_RoleRecngle.right+m_RoleRecngle.width>m_RoleBitDataMap.width )
			{
                m_RoleRecngle.x = 0;
			}else{
			  
				m_RoleRecngle.x += m_RoleRecngle.width; 
			}
				
			m_RoleBitData.copyPixels(m_RoleBitDataMap,m_RoleRecngle,m_RolePoint);
			m_RoleBitMap.scaleX = 1;
			m_RoleBitMap.x = (-bitmapOffsetX) ; 
		}
		
		protected function stopBack():void
		{
			if(standBitmapData!=null && m_RoleBitData!=null && m_RoleBitMap!=null)
			{
				standRectangle.y = standRectangle.height*3;	
				//m_RoleBitData.fillRect(m_RoleRecngle,0);
				clearBitmapdata()
				m_RoleBitData.copyPixels(standBitmapData,standRectangle,m_RolePoint);
				m_RoleBitMap.scaleX = 1;
				m_RoleBitMap.x = (-bitmapOffsetX) ;
			}
			endMove();
		}
		
		protected function moveRight():void{
			if(m_RoleBitDataMap == null) return;
			m_RoleRecngle.y = m_RoleRecngle.height*4;
			
			if( m_RoleRecngle.right+m_RoleRecngle.width>m_RoleBitDataMap.width ){
			 m_RoleRecngle.x = 0;
			}else{
			 m_RoleRecngle.x += m_RoleRecngle.width;
			}
			m_RoleBitData.copyPixels(m_RoleBitDataMap,m_RoleRecngle,m_RolePoint);
			m_RoleBitMap.scaleX = 1;
			m_RoleBitMap.x = (-bitmapOffsetX);
		}
		
		protected function stopRight():void{
			if(standBitmapData!=null && m_RoleBitData!=null && m_RoleBitMap!=null)
			{
				standRectangle.y = standRectangle.height*4;	
				//m_RoleBitData.fillRect(m_RoleRecngle,0);
				clearBitmapdata()
				m_RoleBitData.copyPixels(standBitmapData,standRectangle,m_RolePoint);
				m_RoleBitMap.scaleX = 1;
				m_RoleBitMap.x = (-bitmapOffsetX) ; 
			}
			endMove();
		}
		
		protected function moveLeft():void{
			if(m_RoleBitDataMap == null) return;
			m_RoleRecngle.y = m_RoleRecngle.height*4;
			
			if( m_RoleRecngle.right+m_RoleRecngle.width>m_RoleBitDataMap.width )
			{
			    m_RoleRecngle.x = 0;
			}else{
			    m_RoleRecngle.x += m_RoleRecngle.width;
			}
			m_RoleBitData.copyPixels(m_RoleBitDataMap,m_RoleRecngle,m_RolePoint);
			m_RoleBitMap.scaleX = -1; 
			m_RoleBitMap.x = bitmapOffsetX; 
		}
		
		protected function stopLeft():void
		{
			if(standBitmapData!=null && m_RoleBitData!=null && m_RoleBitMap!=null)
			{
				standRectangle.y = standRectangle.height*4;	
			//m_RoleBitData.fillRect(m_RoleRecngle,0);
			clearBitmapdata()
			m_RoleBitData.copyPixels(standBitmapData,standRectangle,m_RolePoint);
			m_RoleBitMap.scaleX = -1; 
			m_RoleBitMap.x = bitmapOffsetX;
			}
			endMove();
			
		}
		
		protected function moveLeftBack():void
		{
			if(m_RoleBitDataMap == null) return;
			m_RoleRecngle.y = m_RoleRecngle.height*1;
			
			if( m_RoleRecngle.right+m_RoleRecngle.width>m_RoleBitDataMap.width )
			{
			    m_RoleRecngle.x = 0;
			}else{
			    m_RoleRecngle.x += m_RoleRecngle.width;
			}
			m_RoleBitData.copyPixels(m_RoleBitDataMap,m_RoleRecngle,m_RolePoint);
			m_RoleBitMap.scaleX = 1;
			m_RoleBitMap.x = (-bitmapOffsetX); 
		}
		
		protected function stopLeftBack():void
		{
			if(standBitmapData!=null && m_RoleBitData!=null && m_RoleBitMap!=null)
			{
				standRectangle.y = standRectangle.height*1;
				//m_RoleBitData.fillRect(m_RoleRecngle,0);
				clearBitmapdata()
				m_RoleBitData.copyPixels(standBitmapData,standRectangle,m_RolePoint);
				m_RoleBitMap.scaleX = 1;
				m_RoleBitMap.x = (-bitmapOffsetX);
			}
			endMove();
		}
		
		protected function moveRightBack():void
		{
			if(m_RoleBitDataMap == null) return;
			m_RoleRecngle.y = m_RoleRecngle.height*1;
			
			if( m_RoleRecngle.right+m_RoleRecngle.width>m_RoleBitDataMap.width)
			{
			    m_RoleRecngle.x = 0;
			}else{
			     m_RoleRecngle.x += m_RoleRecngle.width;
			}
			m_RoleBitData.copyPixels(m_RoleBitDataMap,m_RoleRecngle,m_RolePoint);
			m_RoleBitMap.scaleX = -1;
			m_RoleBitMap.x = bitmapOffsetX;
		}
		
		protected function stopRightBack():void
		{
			if(standBitmapData!=null && m_RoleBitData!=null && m_RoleBitMap!=null)
			 {
			 	standRectangle.y = standRectangle.height*1;
				 //m_RoleBitData.fillRect(m_RoleRecngle,0);
				 clearBitmapdata()
				 m_RoleBitData.copyPixels(standBitmapData,standRectangle,m_RolePoint);
				 m_RoleBitMap.scaleX = -1;
				 m_RoleBitMap.x = bitmapOffsetX;
			 }
			endMove(); 
		}
		
		protected function moveRightFront():void
		{
			if(m_RoleBitDataMap == null) return;
			m_RoleRecngle.y = 0;//m_RoleRecngle.height*0;
			
			if(m_RoleRecngle.right+m_RoleRecngle.width>m_RoleBitDataMap.width)
			{
				m_RoleRecngle.x = 0;
			}else{
				m_RoleRecngle.x += m_RoleRecngle.width; 
			}
			m_RoleBitData.copyPixels(m_RoleBitDataMap,m_RoleRecngle,m_RolePoint);
			m_RoleBitMap.scaleX = 1; 
			m_RoleBitMap.x = (-bitmapOffsetX); 
		}
		
		protected function stopRightFront():void
		{
			if(standBitmapData!=null && m_RoleBitData!=null && m_RoleBitMap!=null)
			{
				standRectangle.y = 0;//standRectangle.height*4;	
				//m_RoleBitData.fillRect(m_RoleRecngle,0);
				clearBitmapdata()
				m_RoleBitData.copyPixels(standBitmapData,standRectangle,m_RolePoint);
				m_RoleBitMap.scaleX = 1; 
				m_RoleBitMap.x = (-bitmapOffsetX); 
			}
			endMove();	
			
		}
		
		protected function moveLeftFront():void
		{
			if(m_RoleBitDataMap == null) return;
			m_RoleRecngle.y = 0;//m_RoleRecngle.height*4;
			
			if(m_RoleRecngle.right+m_RoleRecngle.width>m_RoleBitDataMap.width)
			{
				m_RoleRecngle.x = 0;
			}else{
				m_RoleRecngle.x += m_RoleRecngle.width;
			}
			m_RoleBitData.copyPixels(m_RoleBitDataMap,m_RoleRecngle,m_RolePoint);
			m_RoleBitMap.scaleX = -1; 
			m_RoleBitMap.x = bitmapOffsetX; 
		}
		
		protected function stopLeftFront():void
		{
			if(standBitmapData!=null && m_RoleBitData!=null && m_RoleBitMap!=null)
			{
				standRectangle.y = 0;//standRectangle.height*4;
			//m_RoleBitData.fillRect(m_RoleRecngle,0);
			clearBitmapdata()
			m_RoleBitData.copyPixels(standBitmapData,standRectangle,m_RolePoint);
			m_RoleBitMap.scaleX = -1;
			m_RoleBitMap.x = bitmapOffsetX; 
			}
			endMove();
		}
		//------------------------以上方法为切割矩阵位图------------------------------------
		
		private function clearBitmapdata():void
		{
			if(m_RoleBitData == null) return;
			var i:uint = 0;
			var j:uint = 0;
			while(j<m_RoleBitData.height)
			{
				j++;
				i = 0;
				while(i<m_RoleBitData.width)
				{
					i++;
					m_RoleBitData.setPixel32(i,j,0);
				}
			}
		}
		
		//移动到下一个节点 
		protected function MoveToNextNode():void
		{
			var moveToEndEvent:Event;
			//不应该出现的异常
			if(m_CurNodeIndex > m_PathArr.length-1)
			{
				standDirection(directionName);
				
				moveToEndEvent = new Event(AvatarEventConst.MOVE_TO_END);
				this.dispatchEvent(moveToEndEvent);
				if(moveOverCallBack != null)
				{
					moveOverCallBack.call();
					moveOverCallBack = null;
					trace("行走异常：当前节点大于最大行走节点数")
				}
				return;
			}
			
			//当前节点与下一个节点数值相同
			if(m_CurNodeIndex>=1 && (m_PathArr[m_CurNodeIndex-1].toString()==m_PathArr[m_CurNodeIndex].toString()))
			{
				m_CurNodeIndex--;
				if(m_CurNodeIndex == 0)
				{
					standDirection(directionName);
					moveToEndEvent = new Event(AvatarEventConst.MOVE_TO_END);
					this.dispatchEvent(moveToEndEvent);
					if(moveOverCallBack != null)
					{
						moveOverCallBack.call();
						moveOverCallBack = null;	
					}
					return;
				}	
			}
			
			//走到最后一个节点。正常走完
			if(m_CurNodeIndex < 1)
			{
				standDirection(directionName);
				moveToEndEvent = new Event(AvatarEventConst.MOVE_TO_END);
				this.dispatchEvent(moveToEndEvent);
				if(moveOverCallBack != null)
				{
					moveOverCallBack.call();
					moveOverCallBack = null;	
				}
				return;
			}
			
			m_GameStop = true;
			//角色往下一个节点移动，确定子路径方向,重置子路径索引和子路径行走长度
			subPath = [m_PathArr[m_CurNodeIndex],m_PathArr[m_CurNodeIndex-1]];
			subPathLen = Math.sqrt( Math.pow( subPath[1][1]-subPath[0][1],2)+Math.pow(subPath[1][0]-subPath[0][0],2) );
			m_MoveAngle = Math.atan2( (subPath[1][1]-subPath[0][1]),(subPath[1][0]-subPath[0][0]) );
			subPathPassLen = 0;
			setDirectionName(m_MoveAngle);
			m_GameStop = false;
			var evt:Event = new Event(AvatarEventConst.MOVE_FOWARD);
			this.dispatchEvent(evt);
		}
		
		/**由Math.atan2()值设置方向名
		 * @param valu: 方向的Math.atan2()值
		 * */
		protected function setDirectionName( valu:Number ):void{
			/*移动方向*/
			var dicValu:int = int(valu*100);
				if( dicValu>=118 && dicValu <=197 ){//front  
					m_DicValue = 0;
					directionName = Direction.Front;
				}else if( dicValu<=-117 && dicValu>=-196){//back  
					m_DicValue = 1;
					directionName = Direction.Back;
				}else if( dicValu>=-38&& dicValu<=39 ){//right 
					m_DicValue = 2;
					directionName = Direction.Right;
				}else if( dicValu>=276 || dicValu<=-275 ){//left  
					m_DicValue = 3;
					directionName = Direction.Left;
				}else if( dicValu>=-275&&dicValu<=-196){//leftBack 
					m_DicValue = 4;
					directionName = Direction.LeftBack;
				}else if( dicValu>=-117 && dicValu<=-38){//rightBack 
					m_DicValue = 5;
					directionName = Direction.RightBack;
				}else if( dicValu>=39 && dicValu<=118 ){//rightFront 
					m_DicValue = 6;
					directionName = Direction.RightFront;
				}else if( dicValu>=197 && dicValu<=276){//left_Front
				    m_DicValue = 7;
				    directionName = Direction.LeftFront;
				}
		}
		
		//角色位移一个步长
		protected function MoveLongStepByStep():void
		{
			var moveToX:int;//移动目标值
			var moveToY:int;
			var moveX:int;//移动量
			var moveY:int;
			var interpolate:Number;//角色在当前子路径两端间的取值比例
			
			//设置当前步长
			if(_status == "walk")
			{
				moveStepLen = roleWalkLenList[lastFrame];
				lastFrame++;
				if(lastFrame > (roleWalkLenList.length-1)) 
					lastFrame = 1;
			}
			else if(_status == "run")
			{
				moveStepLen = roleRunLenList[lastFrame];
				lastFrame++;
				if(lastFrame > (roleRunLenList.length-1))
					lastFrame = 1;
			}
			else if(_status == "jump")
			{
				moveStepLen = roleJumpLenList[lastFrame];
				lastFrame++;
				if(lastFrame > (roleJumpLenList.length-1))
					lastFrame = 1;
			}
			
			//移动距离累加并计算移动目标坐标
			subPathPassLen += moveStepLen;
			if( (subPathLen - subPathPassLen)<moveStepLen )
			{
				moveToX = subPath[1][0];
				moveToY = subPath[1][1];
				subPathPassLen = subPathLen;
			}else{
				interpolate = (subPathPassLen/subPathLen)
				moveToX = interpolate*(subPath[1][0]-subPath[0][0])+subPath[0][0];
			    moveToY = interpolate*(subPath[1][1]-subPath[0][1])+subPath[0][1];
			}
			moveX = moveToX - this.x;
			moveY = moveToY - this.y;
			this.x = int(moveToX);//取整是为了避免角色获取场景遮挡物件时出现一个像素差
			this.y = int(moveToY);
			
			if(subPathPassLen == subPathLen)
			{
				m_CurNodeIndex = m_CurNodeIndex -1;
				MoveToNextNode();
			}
			if(_onMoveStepFun!=null)
			{
				_onMoveStepFun(directionName, moveX, moveY);
			}
		}
		
		
		
		//立即停止位移和切割单帧
		public function endMove():void
		{
			m_GameStop = true;
			lastFrame = 0;
			m_DicValue = 120;
			m_CurNodeIndex = 0;
		}
		
		//按帧频整数倍触发移动
		protected function onEnterFrameHandle(evt:Event=null):void
		{
			if(m_GameStop) return ;
			//当m_MoveStep为m_MoveFrame整数倍时触发。m_MoveStep默认值为1；
			if(m_MoveStep%m_MoveFrame == 0)
			{
				switch(m_DicValue){
					case 0://Front
				        moveFront();
						break;
					case 1://Back
				        moveBack();
						break;
					case 2://Right
				        moveRight();
						break;
					case 3://Left
				        moveLeft();
						break;
					case 4://LeftBack
				        moveLeftBack();
						break;
					case 5://RightBack
				        moveRightBack();
						break;
					case 6://RightFront
				        moveRightFront();
						break;
					case 7://LeftFront
						moveLeftFront();
						break;
				}
				
				MoveLongStepByStep();
				m_MoveStep=1;
			}	
			else
			{
				m_MoveStep++;
			}
		}
		
		/**站立转向
		 * @parma direction: 方向名称，如"Left"，首字母大写
		 * @parma directionNumBer:方向的Math.atan2()值
		 * direction，directionNumBer可任意填其中一个来决定方向
		 * */
		public function standDirection(direction:String=null,directionNumBer:Number=100):void
		{
			if(direction != null)
				directionName = direction;
			if(directionNumBer != 100)
				setDirectionName(directionNumBer);
			
			if(m_RoleBitData == null) return;
			
			switch(directionName)
			{
				case Direction.Front://stop Front
				stopFront();
				break;
				case Direction.Back://stop back
				stopBack();
				break;
				case Direction.Right://stop right
				 stopRight();
				 break;
				case Direction.Left://stop left
				stopLeft();
				break;
				case Direction.LeftBack://stop leftBack
				 stopLeftBack();
				break;
				case Direction.RightBack://stop rightBack
				stopRightBack();
				break;
				case Direction.RightFront://stop right_button
				stopRightFront();
				break;
				case "LeftFront"://stop left_button
				stopLeftFront();
				break;
				case 8://stop
				stopFront();
				break;
			}
		}
		
		//服饰下载并解压完成	
		protected function onDesignLoadOver():void
		{
			actionMC = null;
			iniDesign();
			var evt:Event = new Event(AvatarEventConst.AVATAR_LOADED);
			this.dispatchEvent(evt);
			
			//this.addEventListener( Event.ENTER_FRAME,onEnterFrameHandle);
		}
		
		//从解压的design压缩资源中提取站立和走路已经默认动作的资源
		private function iniDesign():void
		{
			var totalCol:uint = 1;//资源中一行个体数
			var totalRow:uint = 1;//资源中一列个体数
			var ceilWidth:int;//一帧的宽度
			var drawWidth:uint;
			var drawMatrix:Matrix = new Matrix();
			var mcName:String = _natureStatus;
			
			//获取m_RoleBitDataMap资源
			if(m_RoleBitDataMap != null)
				m_RoleBitDataMap.dispose();
			var toDrawObject:DisplayObject;//绘制对象
			if(design == null)
			{
				trace("错误：装配初始化前设置装配");
				return;
			}
			if(design.isAllPart())//如果角色各部位是由整张图片构成
			{
				if(design.all.hasOwnProperty(mcName))//如果资源MC已经命名（老的资源没命名）
					toDrawObject = design.all[mcName];
				else
//tt					toDrawObject = design.all;
				
				
				//如果宽高小于一定的尺寸，则认为整张图就是一帧
				if(toDrawObject.width<560)
				{
					totalCol = 1;
					ceilWidth = toDrawObject.width;
					drawWidth = toDrawObject.width;
				}
				else
				{
					totalCol = 7;
					ceilWidth = Math.round(toDrawObject.width/totalCol);
					drawWidth = toDrawObject.width-ceilWidth
					drawMatrix.tx = -ceilWidth;
				}
					
				if(toDrawObject.height<600)
					totalRow = 1;
				else
					totalRow = 5;
				
				if(toDrawObject.width<1)
				{
					trace("资源制作错误，缺少站立资源");
					return;
				}
				if(standRectangle==null)
					standRectangle = new Rectangle();
				standRectangle.width = ceilWidth;
				standRectangle.height = int(toDrawObject.height/totalRow);
				standRectangle.x = 0;
				standRectangle.y = 0;
				//提取静止站立资源（站立的资源目前做在默认移动方式资源里）
				if(standBitmapData != null)
				{
					standBitmapData.unlock();
					standBitmapData.dispose();
				}//?
				standBitmapData = new BitmapData( standRectangle.width,toDrawObject.height,true,0x00 );
				standBitmapData.draw(toDrawObject);
				standBitmapData.lock();
				
				//设置角色位图移动矩形框
				m_RoleRecngle = standRectangle.clone();
				m_RoleBitDataMap = new BitmapData( drawWidth,toDrawObject.height,true,0x00 );
				m_RoleBitDataMap.draw(toDrawObject,drawMatrix);
				
				//获取默认动作动画
//tt				try{defaultSingleAction = design.all.getActionMC(0,null);}
//tt				catch(e:*){defaultSingleAction=null;}
			}
			else//如果角色各部位是由头、身体、腿、脚构成
			{
				totalCol = 7;
				totalRow = 5;
				
				if(design.head.hasOwnProperty(mcName))
					toDrawObject = design.head[mcName];
				else
//tt					toDrawObject = design.head;
					
				ceilWidth = Math.round(toDrawObject.width/totalCol);
				drawWidth = toDrawObject.width-ceilWidth
				drawMatrix.tx = -ceilWidth;
				
				if(standRectangle==null)
					standRectangle = new Rectangle();
				standRectangle.width = ceilWidth;
				standRectangle.height = int(toDrawObject.height/totalRow);
				standRectangle.x = 0;
				standRectangle.y = 0;
				//设置角色位图移动矩形框
				m_RoleRecngle = standRectangle.clone();
				
				//提取静止站立资源（站立的资源目前做在走路资源里）
				if(standBitmapData != null)
				{
					standBitmapData.unlock();
					standBitmapData.dispose();
				}
				standBitmapData = new BitmapData( standRectangle.width,toDrawObject.height,true,0x00 );
				
				m_RoleBitDataMap = new BitmapData(drawWidth,toDrawObject.height,true,0x00 );
				m_RoleBitDataMap.draw(design.feet[mcName],drawMatrix);
				standBitmapData.draw(design.feet[mcName]);
					
				m_RoleBitDataMap.draw(design.leg[mcName],drawMatrix);
				standBitmapData.draw(design.leg[mcName]);
				
				m_RoleBitDataMap.draw(design.body[mcName],drawMatrix);
				standBitmapData.draw(design.body[mcName]);
					
				m_RoleBitDataMap.draw(design.head[mcName],drawMatrix);
				standBitmapData.draw(design.head[mcName]);
				
				standBitmapData.lock();
				
				//获取默认动作动画
				var arr:Array = new Array();
				
//tt				arr.push(design.feet.getActionMC(0,null));
//tt				arr.push(design.leg.getActionMC(0,null));
//tt				arr.push(design.body.getActionMC(0,null));
//tt				arr.push(design.head.getActionMC(0,null));
//tt				defaultMultiAction = new AvatarMC(arr,standRectangle.clone());
				
			}
			toDrawObject = null;
			
			makeFrame();
		}
		
		//扫描单帧位图的非空像素图的顶部和底部
		protected function scan():void//扫描m_RoleBitData找到实体图像的顶部和底部坐标
		{
			var h:uint = m_RoleBitData.height;
			var w:uint = m_RoleBitData.width-1;
			var centerX:uint = Math.ceil(w/2);
			var currentX:uint;
			var findRealBottom:Boolean = false;//找到实体底部坐标
			var scanFind:Boolean=false;//扫描到实体像素
			while(h >0)
			{
				currentX = centerX;//从中间向两边找
				scanFind = false;
				while(currentX<w)//往右找
				{
					if(m_RoleBitData.getPixel32(currentX,h) != 0)
					{
						if(!scanFind)
						{
							scanFind = true;
							break;
						}
					}
					currentX++;
				}
				if(!scanFind)
				{
					currentX = centerX;
					while(currentX>0)//往左找
					{
						
						if(m_RoleBitData.getPixel32(currentX,h) != 0)
						{
							if(!scanFind)
							{
								scanFind = true;
								break;
							}
						}
						currentX--;
					}
				}
				if(scanFind)
				{
					realBottom = h;
					break;
				}
				h--;
			}
			
			h = 0;
			while(h<m_RoleBitData.height)
			{
				currentX = centerX;//从中间向两边找
				scanFind = false;
				while(currentX<w)//往右找
				{
					if(m_RoleBitData.getPixel32(currentX,h) != 0)
					{
						if(!scanFind)
						{
							scanFind = true;
							break;
						}
					}
					currentX++;
				}
				if(!scanFind)
				{
					currentX = centerX;
					while(currentX>0)//往左找
					{
						
						if(m_RoleBitData.getPixel32(currentX,h) != 0)
						{
							if(!scanFind)
							{
								scanFind = true;
								break;
							}
						}
						currentX--;
					}
				}
				if(scanFind)
				{
					realTop = h;
					break;
				}
				h++;
			}
		}
		
		/**做动作
		 * @param actionID:动作ID。参见《action对照表.txt》
		 * @param param:动作参数
		 * @param cb:动作执行完毕回调
		 * @param actionTime:动作执行时间(单位：秒)，0为播放到最后一帧卸载动画。
		 * */
		public function doAction(actionId:uint,param:String=null,cb:Function=null,actionTime:Number=0):void
		{
			//如果不处于站立状态，则不执行动作
			if(m_DicValue != 120)
				return;
				
			//如果鼠标正放在角色上面，则不播放默认动作
			if(actionId==0 && this.getBounds(this).contains(this.mouseX,this.mouseY))
				return;

			if(param == "") param = null;
			_actionID = actionId;
			_actionTime = actionTime*1000;
			
			if(avatarType != AvatarType.PLAYER)//非玩家（身体不分部位）
			{
				if(actionId == 0)
				{
					actionMC = defaultSingleAction;
					if(actionMC==null)
					{
						flash.utils.clearTimeout(relaxTimeHandle);
						relaxTimeHandle = 0;
						return;
					}
					setAction();
				}
				else
				{
					//获取动作
					if(design.lock)
					{
						trace("资源正在解压");
						return;
					}
//tt					else
//tt						design.getDesign(makeSingleAction,[actionId,param]);
				}
					
			}
			else//角色是分多部位的情况
			{
				if(actionId == 0)
				{
					multiPartActionMC = this.defaultMultiAction;
					if(multiPartActionMC==null)
					{
						flash.utils.clearTimeout(relaxTimeHandle);
						relaxTimeHandle = 0;
						return;
					}
					setAction();
				}
				else
				{
					//获取动作
					if(design.lock)
					{
						trace("资源正在解压");
						return;
					}
//tt					else
//tt						design.getDesign(makeMultiAction,[actionId,param]);
				}
			}
		}
		
		private function setAction():void
		{
			if(avatarType != AvatarType.PLAYER)//非玩家（身体不分部位）
			{
				if(actionMC == null)
					return;
				actionMC.x = 0;
				actionMC.y = 0;
				if(_actionTime == 0)
					actionMC.addEventListener(Event.ENTER_FRAME,checkActionOver);
				else
					timeOutHandle = flash.utils.setTimeout(actionOver,_actionTime);
			}
			else
			{
				if(multiPartActionMC == null)
					return;
				multiPartActionMC.x = 0;
				multiPartActionMC.y = 0;
				timeOutHandle = flash.utils.setTimeout(actionOver,_actionTime);
			}
			//清理动作动画容器
			if(actionSprite == null)
			{
				actionSprite = new Sprite();
				actionSprite.x = -bitmapOffsetX;
				actionSprite.y = -realBottom;
				addChild(actionSprite);
			}
			else
			{
				while(actionSprite.numChildren>0)
				{
					actionSprite.removeChildAt(0);
				}
			}
			if(contains(m_RoleBitMap))
				removeChild(m_RoleBitMap);
				
			if(avatarType != AvatarType.PLAYER)//非玩家（身体不分部位）
			{
				actionMC.x = 0;
				actionMC.y = 0;
				actionSprite.addChild(actionMC);
				if(actionMC.totalFrames>1)
					actionMC.gotoAndPlay(1);
			}
			else
			{
				multiPartActionMC.gotoAndStop(1,directionName);
				actionSprite.addChild(multiPartActionMC);
				multiPartActionMC.playCircularly(_actionTime);//动画播放完时暂停2-5秒后回播
				//actionSprite.x =  -int(actionSprite.width/2);
			}
		}
		
		/**
		 *生成动作动画 
		 * @param param
		 * 
		 */		
		private function makeSingleAction(param:Object):void
		{
//tt			try{actionMC = design.getAllPartActionMC(param[0],param[1]);}
//tt			catch(e:*)
//tt			{
//tt				actionMC=null;
//tt				return;
//tt			}
			setAction();
		}
		
		/**
		 * 
		 * @param param
		 * 
		 */		
		private function makeMultiAction(param:Object):void
		{
			try
			{
//tt				multiPartActionMC = design.all.getActionMC(param[0],param[1]);
//tt				var arr:Array = new Array();
//tt				arr.push(design.feet.getActionMC(param[0],param[1]));
//tt				arr.push(design.leg.getActionMC(param[0],param[1]));
//tt				arr.push(design.body.getActionMC(param[0],param[1]));
//tt				arr.push(design.head.getActionMC(param[0],param[1]));
//tt				multiPartActionMC = new AvatarMC(arr,standRectangle.clone());
			}
			catch(e:*)
			{
				multiPartActionMC=null;
				return;
			}
			setAction();
		}
		
		//当前动作ID
		public function get actionID():uint
		{
			return _actionID;
		}
		
		protected function checkActionOver(evt:Event):void
		{
			if(actionMC == null) return;
			if((actionMC.currentFrame == actionMC.totalFrames) && (_actionTime==0))
			{
				actionOver();
			}
		}
		
		//动作完成，消耗动作动画
		public function actionOver():void
		{
			if(avatarType != AvatarType.PLAYER)//非玩家（身体不分部位）
			{
				if(actionMC == null) return;
				actionMC.stop();
				actionMC.removeEventListener(Event.ENTER_FRAME,checkActionOver);
			}
			else
			{
				if(multiPartActionMC == null) return;
				if(this._actionID != 0)
					multiPartActionMC.destroy();
			}
			
			if(timeOutHandle != 0)
			{
				flash.utils.clearTimeout(timeOutHandle);
				timeOutHandle = 0;
			}
			while(actionSprite.numChildren>0)
			{
				actionSprite.removeChildAt(0);
			}
			
			if(m_RoleBitMap != null) 
				this.addChild(m_RoleBitMap);
		}
		
		//检测鼠标是否与角色非空像素相碰
		public function containPoint(localX:int,localY:int):Boolean
		{
//			if(actionMC==null || actionMC.parent==null)//如果不是在播放动作动画
//			{
				return m_RoleBitMap.bitmapData.hitTest(new Point(-bitmapOffsetX,-realBottom),0,new Point(localX,localY));
//			}
//			else//正在播放动作动画
//			{
//				hitTestRec.x = localX-actionMC.parent.x;
//				hitTestRec.y = localY-actionMC.parent.y;
//				hitTestBMD.setPixel32(hitTestRec.x,hitTestRec.y,0);
//				hitTestBMD.draw(actionMC,null,null,null,hitTestRec);
//				if(hitTestBMD.getPixel32(hitTestRec.x,hitTestRec.y)!=0)
//				{
//					return true;
//				}
//				else
//				{
//					return false;
//				}
//				
//			}
			
		}

		//头部动画资源找不到
		protected function onIOError(evt:IOErrorEvent):void
		{
			trace("头部动画资源找不到："+evt.text);
		}
		
		public function layout():void
		{
			if(m_RoleBitMap.scaleX == 1)
				m_RoleBitMap.x = -bitmapOffsetX;
			else
				m_RoleBitMap.x = bitmapOffsetX;
			m_RoleBitMap.y = -realBottom;
			
		}
		
		public function destroy():void{
			this.m_GameStop = true;
			if(relaxTimeHandle != 0)
			{
				flash.utils.clearTimeout(relaxTimeHandle);
			}
			if(timeOutHandle != 0)
			{
				flash.utils.clearTimeout(timeOutHandle);
			}
			//this.removeEventListener( Event.ENTER_FRAME,onEnterFrameHandle );
			
			if(headMovieTimer != null)
			{
				headMovieTimer.removeEventListener(TimerEvent.TIMER_COMPLETE,removeHeadMovie);
				headMovieTimer = null;
			}
			if(actionMC != null)
			{
				actionMC.removeEventListener(Event.ENTER_FRAME,checkActionOver);
				actionMC = null;
			}
			if(multiPartActionMC != null)
			{
				multiPartActionMC.destroy();
				multiPartActionMC = null;
			}
			if(headMovieLoader != null)
			{
				headMovieLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE,addHeadMovie);
				headMovieLoader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR,onIOError);
			}
			if(m_RoleBitData != null)
			{
				m_RoleBitData.dispose();
				m_RoleBitData = null;
			}
			
			if(m_RoleBitDataMap != null)
			{
				m_RoleBitDataMap.dispose();
				m_RoleBitDataMap = null;
			}
			m_RoleBitMap = null;
			design.destroy();
			design = null;
		}

	}
}